﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace GD.ModelContest.Common
{
public class JavaScript : Page
    {

        #region 服务器端弹出alert对话框 Alert(string str_Message,Page page)

        /// <summary>
        /// 服务器端弹出alert对话框
        /// </summary>
        /// <param name="str_Message">提示信息,例子："请输入您姓名!"</param>
        /// <param name="page">Page类</param>
        /// 示例：fss.Alert("please",Page);
        public static void Alert(string str_Message, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert('" + str_Message + "');</script>");
            return;
        }

        #endregion

        public static void ShowJS(string str, string url, Page page)
        {
            string Comeurl, RJS;
            Comeurl = "";
            url = url.Trim();
            if (url != "")
            {
                RJS = "<script language=Javascript>alert('" + str + "');window.location='" + url + "'</script>";
            }
            else
            {
                if (Comeurl == "")
                {
                    RJS = "<script language=Javascript>alert('" + str + "');history.go(-1)</script>";
                }
                else
                {
                    RJS = "<script language=Javascript>alert('" + str + "');window.location='" + Comeurl + "'</script>";
                }
            }
            page.ClientScript.RegisterStartupScript(page.GetType(), "", RJS);
        }


        #region 服务器端弹出alert对话框 并获得焦点 Alert(string str_Ctl_Name,string str_Message,Page page)

        /// <summary>
        /// 服务器端弹出alert对话框 并获得焦点
        /// </summary>
        /// <param name="str_Ctl_Name">获得焦点控件Id值,比如：txt_Name</param>
        /// <param name="str_Message">提示信息,例子："请输入您姓名!"</param>
        /// <param name="page">Page类</param>
        public static void Alert(string str_Ctl_Name, string str_Message, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert('" + str_Message + "');document.forms(0)." + str_Ctl_Name + ".focus();</script>");
            return;
        }

        #endregion



        #region 服务器端弹出alert对话框并关闭窗口 AlertClose(string str_Message,Page page)

        /// <summary>
        /// 服务器端弹出alert对话框
        /// </summary>
        /// <param name="str_Message">提示信息,例子："请输入您姓名!"</param>
        /// <param name="page">Page类</param>
        /// 示例：fss.Alert("please",Page);
        public static void AlertClose(string str_Message, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert('" + str_Message + "');window.close();</script>");
            return;
        }

        #endregion



        #region  关闭窗口 WindowClose()

        /// <summary>
        /// 服务器端弹出alert对话框
        /// </summary>
        /// <param name="str_Message">提示信息,例子："请输入您姓名!"</param>
        /// <param name="page">Page类</param>
        /// 示例：fss.Alert("please",Page);
        public static void WindowClose(Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>window.close();</script>");
            return;
        }

        #endregion




        #region  刷新到父桢  ReloadToLoginFrame(string url,Page page)

        /// <summary>
        /// 刷新到父桢
        /// </summary>
        /// 一般用于跳转到登陆页面
        /// <param name="Frame">桢名称</param>
        /// <param name="url">连接</param>
        /// <param name="page">page对象</param>
        public static void ReloadToLoginFrame(string url, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language=\"javascript\">parent.document.location.href='" + url + "';</script>");
            return;
        }

        #endregion



        #region 刷新本页窗口 FlashWindow(int MSencond, Page page)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="MSencond"></param>
        /// <param name="page"></param>
        public static void FlashWindow(int MSencond, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>window.setTimeout('location.href=location.href'," + MSencond.ToString() + ");</script>");
            return;
        }
        #endregion


        /// <summary>
        /// 
        /// </summary>
        /// <param name="Msg"></param>
        /// <param name="page"></param>
        public static void WriteJs(string Msg, Page page)
        {
            string strMes = "";
            strMes += "<script language=\'javascript\'>";
            strMes += Msg;
            strMes += "</script>";
            page.ClientScript.RegisterStartupScript(page.GetType(), CommonMethod.GetRandom().ToString(), strMes);
        }
    }

}
